// TODO 快速登录
var Common = function() {
var $body = $('body');
var initialize = function() {
$.ajaxSetup({
global: false,
type: 'POST',
timeout: 60000,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
if('undefined' !== typeof (layer)) {
layer.config({
extend: 'default/retina.css',
shade: 0.2
});
}
if('undefined' !== typeof (NProgress)) {
NProgress.configure({
showSpinner: false
});
}
};
var handleEvent = function() {
if($.support.pjax) {
var $container = $('#pjax-container');
$(document).pjax('a[data-pjax]', '#pjax-container', {
type: 'GET',
timeout: 30000,
scrollTo: $container.length > 0 ? $container.offset().top : 0
});
$(document).on('pjax:send', function() {
NProgress.start();
Common.loading();
});
$(document).on('pjax:complete', function() {
Common.unloading();
NProgress.done(true);
$('#pjax-container').find('img.lazy').lazyload({
effect: 'fadeIn',
});
});
}
$body.find('img.lazy').lazyload({
effect: 'fadeIn',
});
$body.find('[data-toggle="tooltip"]').tooltip({
delay: {
show: 300,
hide: 100
}
});
$body.find('a').on('click', function() {
$body.find('[data-toggle="tooltip"]').tooltip('hide');
});
if('undefined' !== typeof ($.fn.magnificPopup)) {
$body.find('.popup-image').each(function() {
$(this).magnificPopup({
type: 'image',
mainClass: 'mfp-with-zoom',
zoom: {
enabled: true,
duration: 300,
easing: 'ease-in-out',
opener: function(openerElement) {
return openerElement.is('img') ? openerElement : openerElement.find('img');
}
}
});
});
$body.find('.popup-gallery').each(function() {
$(this).magnificPopup({
delegate: 'a',
type: 'image',
tLoading: 'Loading image #%curr%...',
mainClass: 'mfp-img-mobile',
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1]
},
image: {
tError: 'The image #%curr% could not be loaded.',
}
});
});
}
$body.find('.dropdown').each(function() {
var $dropdown = $(this);
var $menu = $dropdown.find('.dropdown-menu');
if($menu.data('click-unclose')) {
$menu.on('click', function(e) {
e.stopPropagation();
});
}
});
$body.on('click', '.ajax-action', function() {
var action = $(this).data('action');
var method = $(this).data('method');
var confirmMsg = $(this).data('confirm');
Common.layerComfirm(confirmMsg, function(idx) {
layer.close(idx);
Common.layerLoad(function() {
$.ajax({
url: action,
type: 'POST',
dataType: 'json',
data: {
'_method': method
},
success: function(response) {
if(1 == response['status']) {
Common.layerMsg(response['msg'], function() {
var data = response['data'];
if(data['url'] && '' != data['url']) {
window.location.replace(data['url']);
} else {
window.location.reload(true);
}
}, 2000);
} else {
Common.layerAlert(2, response['msg']);
}
},
error: function() {
Common.layerMsg(LANG.LANG_0440);
}
});
});
});
return false;
});
$body.find('.form-change-submit').on('change', function() {
var form = $(this).data('form');
if(form && $(form).length > 0) {
$(form).submit();
}
return false;
});
$body.find('.form-control-upload').each(function() {
var $upload = $(this);
$upload.find('input:file').bind('change', function() {
$upload.find('input:text').val($(this).val());
return false;
});
$upload.find('.btn-upload').bind('click', function() {
$upload.find('input:file').trigger('click');
return false;
});
});
// ScrollToTop
var scrollToTop = {
setting: {
startline: 100,
scrollto: 0,
scrollduration: 400,
fadeduration: [500, 100]
},
controlHTML: '',
controlattrs: {offsetx: 30, offsety: 80},
anchorkeyword: "#top",
state: {
isvisible: false,
shouldvisible: false
}, scrollup: function() {
if(!this.cssfixedsupport) {
this.$control.css({opacity: 0});
}
var dest = isNaN(this.setting.scrollto) ? this.setting.scrollto : parseInt(this.setting.scrollto);
if(typeof dest == "string" && jQuery("#" + dest).length == 1) {
dest = jQuery("#" + dest).offset().top;
} else {
dest = 0;
}
this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
}, keepfixed: function() {
var $window = jQuery(window);
var controlx = $window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx;
var controly = $window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety;
this.$control.css({left: controlx + "px", top: controly + "px"});
}, togglecontrol: function() {
var scrolltop = jQuery(window).scrollTop();
if(!this.cssfixedsupport) {
this.keepfixed();
}
this.state.shouldvisible = (scrolltop >= this.setting.startline) ? true : false;
if(this.state.shouldvisible && !this.state.isvisible) {
this.$control.stop().animate({opacity: 1}, this.setting.fadeduration[0]);
this.state.isvisible = true;
} else {
if(this.state.shouldvisible == false && this.state.isvisible) {
this.$control.stop().animate({opacity: 0}, this.setting.fadeduration[1]);
this.state.isvisible = false;
}
}
}, init: function() {
jQuery(document).ready(function($) {
var mainobj = scrollToTop;
var iebrws = document.all;
mainobj.cssfixedsupport = !iebrws || iebrws && document.compatMode == "CSS1Compat" && window.XMLHttpRequest;
mainobj.$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $("html") : $("body")) : $("html,body");
mainobj.$control = $('